// --------------------------
//   Server Action Class 
// -------------------------

			 
function ServerAction (actionName,onLoadFunction) {										
	if (actionName) this.setAction(actionName);
	if (onLoadFunction) this.setOnLoadFunction(onLoadFunction);
}

ServerAction.setPath = function (path) {
	ServerAction.path = path;
}

ServerAction.scriptName = "action.php";
			 
ServerAction.prototype.setAction = function (actionName) {
	this.actionName = actionName;
}
			 
ServerAction.prototype.setOnLoadFunction = function (onLoadFunction) {
	this.onLoadFunction = onLoadFunction;
}
			 
ServerAction.prototype.setParam = function (name,value){
	if (!this.params) this.params = new Object();
	this.params[name] = value;
}
			 
ServerAction.prototype.getUrl= function () {
	var url= ServerAction.path + ServerAction.scriptName + "?nocache="+Math.random()+"&action=" + this.actionName;
	if (this.params) {
		url+= "&";
		for (var prop in this.params) {
			url += prop + "=" + this.params[prop];
		}
	}			
	return url;
}
			 
ServerAction.prototype.send = function () {
	var url = this.getUrl();
	this.onLoadFunction != undefined ? _IG_FetchXmlContent(url,this.onLoadFunction) : _IG_FetchXmlContent(url);
}
			 
			 
// ---------------------------------------
//   			DoodleData Class 
// ---------------------------------------
			
function DoodleData (rawData) {
	
	if (rawData) this.setXML(rawData);
}

function getXmlTextDefault(node, defaultText) {
	if(node == null || typeof node == 'undefined' 
	|| node.firstChild == null || typeof node.firstChild == 'undefined' 
	|| node.firstChild.nodeValue == null || typeof node.firstChild.nodeValue == 'undefined') {
		return defaultText;
	} else {
		return node.firstChild.nodeValue;
	}
}
			
DoodleData.prototype.setXML = function (rawData) {
	
	rawData = rawData.getElementsByTagName("object")[0];

	this._author = new DoodleAuthorData(rawData.getElementsByTagName("author")[0]);

	this._name = getXmlTextDefault(rawData.getElementsByTagName("name")[0], "No Name");

	this._description = getXmlTextDefault(rawData.getElementsByTagName("description")[0], "No Description");
	this._id = getXmlTextDefault(rawData.getElementsByTagName("id")[0], "No ID");
	this._url = getXmlTextDefault(rawData.getElementsByTagName("url")[0], "No URL");
	
	/*
	if (rawData.attributes['id'] ) {
		//ie workaround
		this._id = rawData.attributes['id'].value;
	} else {
		this._id  = rawData.getAttribute("id");
	}
	*/
																 
}

DoodleData.prototype.getId = function (rawData) {
	return this._id;
}

DoodleData.prototype.getTitle = function (rawData) {
	return  this._title;
}

DoodleData.prototype.getUrl = function (rawData) {
	return  this._url;
}

DoodleData.prototype.getDescription = function (rawData) {
	return this. _description;
}

DoodleData.prototype.getAuthor = function (rawData) {
	return  this._author;
}

DoodleData.prototype.getSchool = function (rawData) {
	return  this._author.getSchool();
}

	
	
	
// ---------------------------------------
//   			SchoolData Class 
// ---------------------------------------
			
function DoodleSchoolData (rawData) {
	if (rawData) this.setXML(rawData);
}
			
DoodleSchoolData.prototype.setXML = function (rawData) {
	
	
	this._name = getXmlTextDefault(rawData.getElementsByTagName("name")[0], "No Name");
	this._postcode = getXmlTextDefault(rawData.getElementsByTagName("postcode")[0], "No Postcode");
	this._state = getXmlTextDefault(rawData.getElementsByTagName("state")[0], "No State");
	this._id = getXmlTextDefault(rawData.getElementsByTagName("id")[0], "No ID");
	
	/*
	if (rawData.attributes['id'] ) {
		//ie workaround
		this._id = rawData.attributes['id'].value;
	} else {
		this._id  = rawData.getAttribute("id");
	}*/
	
}

DoodleSchoolData.prototype.getId = function () {
	return this._id;
}

DoodleSchoolData.prototype.getName = function () {
	return this._name;
}

DoodleSchoolData.prototype.getSuburb = function () {
	return this._suburb;
}

DoodleSchoolData.prototype.getState = function () {
	return this._state;
}


// ---------------------------------------
//   			AuthorData Class 
// ---------------------------------------
			
function DoodleAuthorData (rawData) {
	if (rawData) this.setXML(rawData);
}
			
DoodleAuthorData.prototype.setXML = function (rawData) {	
	
	this._school = new DoodleSchoolData(rawData.getElementsByTagName("school")[0]);
	
	this._name = getXmlTextDefault(rawData.getElementsByTagName("name")[0], "No Name");
	this._year = getXmlTextDefault(rawData.getElementsByTagName("year")[0], "No Year");
	this._id = getXmlTextDefault(rawData.getElementsByTagName("id")[0], "No ID");

	/*
	if (rawData.attributes['id'] ) {
		//ie workaround
		this._id = rawData.attributes['id'].value;
	} else {
		this._id  = rawData.getAttribute("id");
	}
	*/
}

DoodleAuthorData.prototype.getId = function () {
	return this._id;
}

DoodleAuthorData.prototype.getName = function () {
	return this._name;
}

DoodleAuthorData.prototype.getYear = function () {
	return this._year;
}

DoodleAuthorData.prototype.getSchool = function () {
	return this._school;
}
